home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 3.2 KB | 122 lines | [TEXT/MPS ] |
- //
- //
- //
- // The Following Code is Specific to Play-from-Wave type operations
- //
- //
- //
-
- #pragma load "MacHeaders"
-
-
- #ifndef __MAININCLUDES__
- #include "MainApp.h"
- #endif
-
- #ifndef __DOUBLEBUFFERINCLUDES__
- #include "DoubleBuffer.h"
- #endif
-
- extern SndChannelPtr gSndChan;
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // High Level routine that plays a wave form...
-
- void PlayWave (long durration, WaveCyclePtr theWave, Ptr *privateData)
- {
- OSErr err;
- SoundHeader theHeader;
-
- // Fake a sound header for the wave we're going to play
- theHeader.samplePtr = nil;
- theHeader.length = nil;
- theHeader.sampleRate = (Fixed) 0x56ee8ba3; // 22kHz constant
- theHeader.loopStart = nil;
- theHeader.loopEnd = nil;
-
- err = DoubleBuffer(gSndChan, (unsigned long)theWave, (ProcPtr)WaveReadProc, (ProcPtr)nil,
- &theHeader, durration, nil, privateData);
- }
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // read procedure for retrieving sound data from the wave spec
- OSErr WaveReadProc (void *private, short bufNum, Boolean asynch)
- {
- OSErr err = noErr;
- long oldA5 = nil;
- long rdSize = 0;
- register strippedDownReadPBPtr pb = nil;
- PrivateDBInfoPtr dbInfo;
-
- dbInfo = (PrivateDBInfoPtr) private;
-
- if (dbInfo->bytesToGo == 0) // No Bytes to read? bail
- err = eofErr;
- else {
-
- // Again, optimizing out some of these de-references
- pb = &(dbInfo->buffers[bufNum].readPB.pb);
-
- if (dbInfo->bytesToGo > kBufferSize)
- rdSize = kBufferSize;
- else
- rdSize = dbInfo->bytesToGo;
-
- pb->ioFRefNum = dbInfo->refNum; // set up the paramBlock
- pb->ioBuffer = dbInfo->buffers[bufNum].header->samplePtr;
- pb->ioReqCount = rdSize;
- pb->ioPosMode = fsAtMark;
- pb->ioPosOffset =0;
- dbInfo->buffers[bufNum].readPB.userInfo = (Ptr)dbInfo;
- dbInfo->buffers[bufNum].readPB.headerNum = bufNum;
-
- ReadWave ((WaveCyclePtr) dbInfo->refNum, rdSize, pb->ioBuffer); // Get the Data
-
- if (asynch) {
- pb->ioCompletion = (ProcPtr)&CompleteRead; // This is a formality
- putPB (pb); // Stuff PB on (A0)
- CompleteRead ();
- } else
- pb->ioCompletion = nil;
-
- dbInfo->bytesToGo -= rdSize;
-
- dbInfo->buffers[bufNum].header->length = rdSize;
-
- // if we were called synchronously, chances are we care about the when we hit the
- // "End of File", so if rdSize is less than the buffersize we know this was the
- // last buffer read...
- if (rdSize < kBufferSize)
- err = eofErr;
-
- }
- return (err);
- }
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // ReadWave makes a wave snippet look like a continuous wave form to the caller
- void ReadWave (WaveCyclePtr theWave, unsigned short reqBytes, Ptr buffer)
- {
- static unsigned short mark = 0;
- unsigned short xferSize = 0;
-
- while (reqBytes > 0) {
-
- // Figure out how many bytes to the end of the wave
- xferSize = (theWave->length - mark);
-
- // Make sure we're "reading" the appropriate number of bytes
- if (reqBytes < xferSize)
- xferSize = reqBytes;
-
- BlockMove ((theWave->wavePtr + mark), buffer, xferSize);
-
- buffer += xferSize;
- reqBytes -= xferSize;
-
- mark += xferSize;
- if (mark >= theWave->length)
- mark = 0;
- }
- }
-